<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <!-- 商品区块 -->
    <goods-item v-for="(item, index) in hotList" :key="index" :goods="item" />
  </div>
</template>
<script>
import { computed, ref } from "vue";
import GoodsItem from "@/views/Category/components/goods-item";
import { reqFindHotGoods } from "@/api/goods";
import { useRoute } from "vue-router";
export default {
  name: "GoodsHot",
  components: {
    GoodsItem,
  },
  props: {
    type: {
      type: Number,
      default: 1,
    },
  },
  setup(props) {
    const hotList = ref([]);
    const route = useRoute();
    // 标题对象
    const titleObj = {
      1: "24小时热销榜",
      2: "周热销榜",
      3: "总热销榜",
    };
    const title = computed(() => {
      return titleObj[props.type];
    });

    const getHots = async () => {
      const res = await reqFindHotGoods({
        id: route.params.id,
        type: props.type,
        limit: 3,
      });
      hotList.value = res.result;
    };
    getHots();
    return { title, hotList };
  },
};
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>
